﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent

Partial Class rtransview
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Or Session("StaffType").ToString = "2" Then
            Response.Redirect("Default.aspx")
        Else
            lblhidStaffId.Text = Session("StaffId").ToString
            lblhidStaffType.Text = Session("StaffType").ToString
        End If

        If Not Page.IsPostBack Then
            If Not Session("Tid").ToString Is Nothing Then
                lblhidTransId.Text = Session("Tid").ToString
                'Me.Session.Remove("Tid")
                LoadTransInfo()
                Dim strCoBroke As String = String.Empty
                If lblhidCoBrokeAgencyName.Text <> String.Empty Then
                    strCoBroke += "Agency Name : " & lblhidCoBrokeAgencyName.Text.Trim & "<br />"
                End If
                If lblhidCoBrokePhone.Text <> String.Empty Then
                    strCoBroke += "Phone : " & lblhidCoBrokePhone.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeMobile.Text <> String.Empty Then
                    strCoBroke += "Mobile : " & lblhidCoBrokeMobile.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeFax.Text <> String.Empty Then
                    strCoBroke += "Fax : " & lblhidCoBrokeFax.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeEmail.Text <> String.Empty Then
                    strCoBroke += "Email : " & lblhidCoBrokeEmail.Text.Trim & "<br />"
                End If
                lblCoBroke.Attributes.Add("onmouseover", "return overlib('" & strCoBroke & "',ABOVE);")
            Else
                Response.Redirect("TransList.aspx")
            End If
        End If
    End Sub

    Private Sub LoadTransInfo()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT t.TransactionId, t.PropertyId, t.OpenFileRef, t.CloseFileRef, t.InvoiceNumber, t.TransListType, " & _
                                "p.UnitNumber + ', ' + r.Road + ', ' + o.Location + ', ' + s.State + ', ' + y.Country as 'Address', t.Status, " & _
                                "j.Project, t.ListerId, t.TransactorId, L.Name as Lister, L.Initial as ListerInitial, t.ListDate, t.LandlordType, t.LandlordName1, t.LandlordName2, " & _
                                "t.LandlordName3, t.LandlordCompany, t.LandlordNRIC1, t.LandlordNRIC2, t.LandlordNRIC3, a.Name as Transactor, a.Initial as TransactorInitial, " & _
                                "t.LandlordCompanyNo, t.LandlordAddress, t.LandlordPhone, t.LandlordMobile, t.LandlordFax, t.LandlordContactPerson, " & _
                                "t.LandlordEmail, t.LandlordReferral, t.LandlordReferralName, t.LandlordReferralNRIC, t.TransactDate, " & _
                                "t.LandlordReferralContact, t.LandlordReferralStatus, t.LandlordReferralAmount, t.LandlordReferralAmtSum, " & _
                                "t.LandlordViewMeetTele, t.LandlordIncomeTax, t.LandlordTAFee, t.AgencyFee, t.GST, t.GSTPaidBy, t.ListingFee, " & _
                                "t.TenantType, t.TenantName1, t.TenantName2, t.TenantName3, t.TenantCompany, " & _
                                "t.TenantNRIC1, t.TenantNRIC2, t.TenantNRIC3, t.TenantCompanyNo, t.TenantAddress, " & _
                                "t.TenantPhone, t.TenantMobile, t.TenantFax, t.TenantEmail, t.TenantReferral, " & _
                                "t.TenantReferralName, t.TenantReferralNRIC, t.TenantReferralContact, t.TenantViewMeetTele, t.TenantIncomeTax, " & _
                                "t.TenantReferralStatus, t.TenantReferralAmount, t.TenantReferralAmtSum, t.TenantContactPerson, " & _
                                "t.DisbursementFee, t.CoBroke, t.Deposit, t.DepositMonth, t.Advance, t.AdvanceMonth, t.WaterElectric, t.Tel, t.TenantTAFee, " & _
                                "t.CoBrokeId, c.Name as CoBrokeName, c.AgencyName as CoBrokeAgencyName, c.Phone as CoBrokePhone, " & _
                                "c.Mobile as CobrokeMobile, c.Fax as CobrokeFax, c.Email as cobrokeEmail, t.TransListType, " & _
                                "t.MonthlyRental, t.TenancyDuration, t.Requisition, t.TerminationClause, t.PremiseUse, " & _
                                "t.TotalAgencyFee, t.ListerAmt, t.ReferralAmt, t.GovAmt, t.GrossAmount, TotalTA, StampDuty, p.RListerId, " & _
                                "t.CommencementDate, t.SignDate, t.SignComplete, t.SignCompleteDate, SC.Name as SignCompleteBy, t.CollectDate, t.CollectAmt, " & _
                                "t.CollectComplete, CC.Name as CollectCompleteBy, t.CollectCompleteDate, t.UndoDate, t.UndoRemark, t.UndoAmt, t.UndoAmt, UB.Name as UndoBy, " & _
                                "CASE t.TenancyDurationType WHEN 0 THEN 'YEARS' WHEN 1 THEN 'MONTHS' ELSE 'DAYS' END as TenancyDurationType " & _
                                "FROM AW_RentTransaction t LEFT JOIN AW_Staff L on t.ListerId = L.StaffId LEFT JOIN AW_Staff a on t.Transactorid = a.StaffId " & _
                                "LEFT JOIN AW_Staff SC on t.SignCompleteBy = SC.StaffId LEFT JOIN AW_Staff CC on t.CollectCompleteBy = CC.StaffId " & _
                                "LEFT JOIN AW_Staff UB on t.UndoBy = UB.StaffId " & _
                                "LEFT JOIN AW_CoBroke c on t.CoBrokeId = c.CoBrokeId LEFT OUTER JOIN AW_Property p ON p.PropertyId = t.PropertyId " & _
                                "LEFT OUTER JOIN AW_Road r ON p.RoadId = r.RoadId LEFT OUTER JOIN AW_Location o ON r.LocationId = o.LocationId " & _
                                "LEFT OUTER JOIN AW_State s ON o.StateId = s.StateId LEFT OUTER JOIN AW_Country y ON s.CountryId = y.CountryId " & _
                                "LEFT OUTER JOIN AW_Project j ON p.ProjectId = j.ProjectId WHERE TransactionID=@TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidTransId.Text.Trim))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        For Each ReadRow As Data.DataRow In TempDT.Rows
            lblhidPropertyId.Text = ReadRow.Item("PropertyId").ToString
            Select Case ReadRow.Item("Status").ToString
                Case "0"
                    lblCurrentStatus.Text = "NEW"
                Case "1"
                    lblCurrentStatus.Text = "PENDING SIGNING"
                Case "2"
                    lblCurrentStatus.Text = "PENDING COLLECTION"
                Case "3"
                    If ReadRow.Item("UndoDate").ToString = "" Then
                        lblCurrentStatus.Text = "COMPLETED"
                    Else
                        lblCurrentStatus.Text = "COMPLETED (ABORTED)"
                    End If

                Case "4"
                    lblCurrentStatus.Text = "RELISTED"
                Case "5"
                    lblCurrentStatus.Text = "RENEWED"
            End Select
            Select Case ReadRow.Item("TransListType").ToString
                Case "1"
                    lblTransact.Text = "RR"
                Case "2"
                    lblTransact.Text = "RC"
                Case "3"
                    lblTransact.Text = "RL"
                Case "4"
                    lblTransact.Text = "RI"
            End Select
            lblOpenFileNum.Text = ReadRow.Item("OpenFileRef").ToString
            If ReadRow.Item("InvoiceNumber").ToString = "" Then
                trInvoiceNum.Visible = False
            Else
                lblInvoiceNum.Text = ReadRow.Item("InvoiceNumber").ToString
                trInvoiceNum.Visible = True
            End If
            If ReadRow.Item("CloseFileRef").ToString = "" Then
                trCloseFileNum.Visible = False
            Else
                lblCloseFileNum.Text = ReadRow.Item("CloseFileRef").ToString
                trCloseFileNum.Visible = True
            End If
            'lblListBy.Text = ReadRow.Item("Lister").ToString
            'lblTransactBy.Text = ReadRow.Item("Transactor").ToString
            lblListBy.Text = ReadRow.Item("ListerInitial").ToString
            lblTransactBy.Text = ReadRow.Item("TransactorInitial").ToString
            If ReadRow.Item("Project").ToString = "" Then
                trProjecName.Visible = False
            Else
                lblProjectName.Text = ReadRow.Item("Project").ToString
                trProjecName.Visible = True
            End If
            lblPremise.Text = ReadRow.Item("Address").ToString
            lblListDate.Text = Format(ReadRow.Item("ListDate"), "dd-MMM-yyyy")
            lblTransactDate.Text = Format(ReadRow.Item("TransactDate"), "dd-MMM-yyyy")
            lblMonthlyRental.Text = String.Format("{0:#,##0.00}", ReadRow.Item("MonthlyRental"))
            lblDurationTenancy.Text = ReadRow.Item("TenancyDuration").ToString & " " & ReadRow.Item("TenancyDurationType").ToString
            lblTerminationClause.Text = ReadRow.Item("TerminationClause").ToString
            lblRequisition.Text = ReadRow.Item("Requisition").ToString
            lblCoBroke.Text = ReadRow.Item("CoBrokeName").ToString
            lblhidCoBrokeId.Text = ReadRow.Item("CoBrokeId").ToString
            lblhidCoBrokeAgencyName.Text = ReadRow.Item("CoBrokeAgencyName").ToString
            lblhidCoBrokePhone.Text = ReadRow.Item("CoBrokePhone").ToString
            lblhidCoBrokeMobile.Text = ReadRow.Item("CobrokeMobile").ToString
            lblhidCoBrokeFax.Text = ReadRow.Item("CobrokeFax").ToString
            lblhidCoBrokeEmail.Text = ReadRow.Item("cobrokeEmail").ToString
            If ReadRow.Item("LandlordName1").ToString = "" Then
                trLName1.Visible = False
            Else
                trLName1.Visible = True
                lblName1.Text = ReadRow.Item("LandlordName1").ToString
            End If
            If ReadRow.Item("LandlordName2").ToString = "" Then
                trLName2.Visible = False
            Else
                trLName2.Visible = True
                lblName2.Text = ReadRow.Item("LandlordName2").ToString
            End If
            If ReadRow.Item("LandlordName3").ToString = "" Then
                trLName3.Visible = False
            Else
                trLName3.Visible = True
                lblName3.Text = ReadRow.Item("LandlordName3").ToString
            End If
            If ReadRow.Item("LandlordCompany").ToString = "" Then
                trLCompanyName.Visible = False
            Else
                trLCompanyName.Visible = True
                lblCompanyName.Text = ReadRow.Item("LandlordCompany").ToString
            End If
            If ReadRow.Item("LandlordNRIC1").ToString = "" Then
                trLNRIC1.Visible = False
            Else
                trLNRIC1.Visible = True
                lblNRIC1.Text = ReadRow.Item("LandlordNRIC1").ToString
            End If
            If ReadRow.Item("LandlordNRIC2").ToString = "" Then
                trLNRIC2.Visible = False
            Else
                trLNRIC2.Visible = True
                lblNRIC2.Text = ReadRow.Item("LandlordNRIC2").ToString
            End If
            If ReadRow.Item("LandlordNRIC3").ToString = "" Then
                trLNRIC3.Visible = False
            Else
                trLNRIC3.Visible = True
                lblNRIC3.Text = ReadRow.Item("LandlordNRIC3").ToString
            End If
            If ReadRow.Item("LandlordCompanyNo").ToString = "" Then
                trLCompanyNo.Visible = False
            Else
                trLCompanyNo.Visible = True
                lblCompanyNo.Text = ReadRow.Item("LandlordCompanyNo").ToString
            End If
            lblContacPerson.Text = ReadRow.Item("LandlordContactPerson").ToString
            lblMobile.Text = ReadRow.Item("LandlordMobile").ToString
            If ReadRow.Item("LandlordReferral").ToString = "0" Then
                trLRefer.Visible = False
            Else
                trLRefer.Visible = True
            End If
            If ReadRow.Item("TenantName1").ToString = "" Then
                trTName1.Visible = False
            Else
                trTName1.Visible = True
                lblTName1.Text = ReadRow.Item("TenantName1").ToString
            End If
            If ReadRow.Item("TenantName2").ToString = "" Then
                trTName2.Visible = False
            Else
                trTName2.Visible = True
                lblTName2.Text = ReadRow.Item("TenantName2").ToString
            End If
            If ReadRow.Item("TenantName3").ToString = "" Then
                trTName3.Visible = False
            Else
                trTName3.Visible = True
                lblTName3.Text = ReadRow.Item("TenantName3").ToString
            End If
            If ReadRow.Item("TenantCompany").ToString = "" Then
                trTCompanyName.Visible = False
            Else
                trTCompanyName.Visible = True
                lblTCompanyName.Text = ReadRow.Item("TenantCompany").ToString
            End If
            If ReadRow.Item("TenantNRIC1").ToString = "" Then
                trTNRIC1.Visible = False
            Else
                trTNRIC1.Visible = True
                lblTNRIC1.Text = ReadRow.Item("TenantNRIC1").ToString
            End If
            If ReadRow.Item("TenantNRIC2").ToString = "" Then
                trTNRIC2.Visible = False
            Else
                trTNRIC2.Visible = True
                lblTNRIC2.Text = ReadRow.Item("TenantNRIC2").ToString
            End If
            If ReadRow.Item("TenantNRIC3").ToString = "" Then
                trTNRIC3.Visible = False
            Else
                trTNRIC3.Visible = True
                lblTNRIC3.Text = ReadRow.Item("TenantNRIC3").ToString
            End If
            If ReadRow.Item("TenantCompanyNo").ToString = "" Then
                trTCompanyNo.Visible = False
            Else
                trTCompanyNo.Visible = True
                lblTCompanyNo.Text = ReadRow.Item("TenantCompanyNo").ToString
            End If
            lblTContactPerson.Text = ReadRow.Item("TenantContactPerson").ToString
            lblTMobile.Text = ReadRow.Item("TenantMobile").ToString
            If ReadRow.Item("TenantReferral").ToString = "0" Then
                trTRefer.Visible = False
            Else
                trTRefer.Visible = True
            End If
            If ReadRow.Item("Deposit").ToString = "0" Then
                trDeposit.Visible = False
            Else
                trDeposit.Visible = True
                lblDeposit.Text = ReadRow.Item("DepositMonth").ToString & " month(s) of " & Format(ReadRow.Item("Deposit"), "#,##0.00")
            End If
            If ReadRow.Item("Advance").ToString = "0" Then
                trAdvance.Visible = False
            Else
                trAdvance.Visible = True
                lblAdvance.Text = ReadRow.Item("AdvanceMonth").ToString & " month(s) of " & Format(ReadRow.Item("Advance"), "#,##0.00")
            End If
            If ReadRow.Item("WaterElectric").ToString = "0" Then
                trWaterElectric.Visible = False
            Else
                trWaterElectric.Visible = True
                lblWaterElectric.Text = Format(ReadRow.Item("WaterElectric"), "#,##0.00")
            End If
            If ReadRow.Item("Tel").ToString = "0" Then
                trTel.Visible = False
            Else
                trTel.Visible = True
                lblTel.Text = String.Format("{0:#,##0.00}", ReadRow.Item("Tel"))
            End If
            lblAgencyFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TotalAgencyFee"))
            lblLister.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListerAmt"))
            lblReferral.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ReferralAmt"))
            lblStampDuty.Text = String.Format("{0:#,##0.00}", ReadRow.Item("StampDuty"))
            lblGov.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GovAmt"))
            lblTAFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TotalTA"))
            lblGrossAmount.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GrossAmount"))
            Select Case ReadRow.Item("SignComplete").ToString
                Case "0"
                    lblSignStatus.Text = "PENDING SIGNING"
                Case "1"
                    lblSignStatus.Text = "COMPLETED SIGNING (By " & ReadRow.Item("SignCompleteBy").ToString & " on " & Format(ReadRow.Item("SignCompleteDate"), "dd-MMM-yyyy") & ")"
                Case Else
                    lblSignStatus.Text = ""
            End Select
            If ReadRow.Item("CommencementDate").ToString = "" Then
                lblSPDate.Text = ""
            Else
                lblSPDate.Text = Format(ReadRow.Item("CommencementDate"), "dd-MMM-yyyy")
            End If
            If ReadRow.Item("SignDate").ToString = "" Then
                lblSignDate.Text = ""
            Else
                lblSignDate.Text = Format(ReadRow.Item("SignDate"), "dd-MMM-yyyy")
            End If

            Select Case ReadRow.Item("CollectComplete").ToString
                Case "0"
                    If ReadRow.Item("SignComplete").ToString = "0" Then
                        trCollection.Visible = False
                        trActualCollection.Visible = False
                        trCollectAmt.Visible = False
                    Else
                        trCollection.Visible = True
                        trActualCollection.Visible = True
                        trCollectAmt.Visible = True
                        lblCollectStatus.Text = "PENDING COLLECTION"
                        If ReadRow.Item("CollectDate").ToString = "" Then
                            lblCollectionDate.Text = ""
                        Else
                            lblCollectionDate.Text = Format(ReadRow.Item("CollectDate"), "dd-MMM-yyyy")
                        End If
                        lblAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("CollectAmt"))
                    End If
                Case "1"
                    trCollection.Visible = True
                    trActualCollection.Visible = True
                    trCollectAmt.Visible = True
                    lblCollectStatus.Text = "COMPLETED COLLECTION (By " & ReadRow.Item("CollectCompleteBy").ToString & " on " & Format(ReadRow.Item("CollectCompleteDate"), "dd-MMM-yyyy") & ")"
                    If ReadRow.Item("CollectDate").ToString = "" Then
                        lblCollectionDate.Text = ""
                    Else
                        lblCollectionDate.Text = Format(ReadRow.Item("CollectDate"), "dd-MMM-yyyy")
                    End If
                    lblAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("CollectAmt"))
                Case Else
                    trCollection.Visible = False
                    trActualCollection.Visible = False
                    trCollectAmt.Visible = False
            End Select
            If ReadRow.Item("UndoDate").ToString = "" Then
                trAbortStatus.Visible = False
                trAbortDAte.Visible = False
                trAbortRemark.Visible = False
                trAbortAmt.Visible = False
            Else
                If ReadRow.Item("SignComplete").ToString = "" Or ReadRow.Item("SignComplete").ToString = "0" Then
                    trSign.Visible = False
                    trCommencementDate.Visible = False
                    trActualSignDate.Visible = False
                Else
                    trSign.Visible = True
                    trCommencementDate.Visible = True
                    trActualSignDate.Visible = True
                End If
                If ReadRow.Item("CollectComplete").ToString = "" Or ReadRow.Item("CollectComplete").ToString = "0" Then
                    trCollection.Visible = False
                    trActualCollection.Visible = False
                    trCollectAmt.Visible = False
                Else
                    trCollection.Visible = True
                    trActualCollection.Visible = True
                    trCollectAmt.Visible = True
                End If
                trAbortStatus.Visible = True
                trAbortDAte.Visible = True
                trAbortRemark.Visible = True
                trAbortAmt.Visible = True
                lblAbortStatus.Text = "ABORTED (By " & ReadRow.Item("UndoBy").ToString & " on " & Format(ReadRow.Item("UndoDate"), "dd-MMM-yyyy")
                lblAbortDAte.Text = Format(ReadRow.Item("UndoDate"), "dd-MMM-yyyy")
                lblAbortRemark.Text = ReadRow.Item("UndoRemark").ToString
                lblAbortAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("UndoAmt"))
            End If

        Next
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub
End Class
